aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/[groupId]/expenses/create/page.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/groups/[groupId]/expenses/create/page.tsx')
-rw-r--r--src/app/groups/[groupId]/expenses/create/page.tsx37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/app/groups/[groupId]/expenses/create/page.tsx b/src/app/groups/[groupId]/expenses/create/page.tsx
new file mode 100644
index 0000000..f8d0ff9
--- /dev/null
+++ b/src/app/groups/[groupId]/expenses/create/page.tsx
@@ -0,0 +1,37 @@
+import { ExpenseForm } from '@/components/expense-form'
+import { Button } from '@/components/ui/button'
+import { createExpense, getGroup } from '@/lib/api'
+import { expenseFormSchema } from '@/lib/schemas'
+import { ChevronLeft } from 'lucide-react'
+import Link from 'next/link'
+import { notFound, redirect } from 'next/navigation'
+
+export default async function ExpensePage({
+ params: { groupId },
+}: {
+ params: { groupId: string }
+}) {
+ const group = await getGroup(groupId)
+ if (!group) notFound()
+
+ async function createExpenseAction(values: unknown) {
+ 'use server'
+ const expenseFormValues = expenseFormSchema.parse(values)
+ await createExpense(expenseFormValues, groupId)
+ redirect(`/groups/${groupId}`)
+ }
+
+ return (
+ <main>
+ <div className="mb-4">
+ <Button variant="ghost" asChild>
+ <Link href={`/groups/${groupId}`}>
+ <ChevronLeft className="w-4 h-4 mr-2" /> Back to group
+ </Link>
+ </Button>
+ </div>
+
+ <ExpenseForm group={group} onSubmit={createExpenseAction} />
+ </main>
+ )
+}